home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / HyperCard / Pictoids 2.0 / BitMapToRegion ƒ / BMTR Patcher.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-03  |  2.5 KB  |  155 lines  |  [TEXT/KAHL]

  1. /* Multi-purpose BMTR Installer
  2.  
  3.    Written by Nigel Perry, 1990,1991. This is in the PUBLIC DOMAIN.
  4.  
  5.  */
  6.  
  7. #include "BMTRconfig.h"
  8.  
  9. #ifdef XCMD
  10. #define RSRC
  11. #include <HyperXCmd.h>
  12. #endif
  13.  
  14. #ifdef INIT
  15. #define RSRC
  16. #endif
  17.  
  18. #define _BitMapToRegion                 0xA8D7
  19. #define _Unimplemented                    0xA89F
  20.  
  21. #define NIL ((void *)0)
  22. #define EMPTY ((char *)0xA02)        /* low memory global OneOne */
  23.                                     /* used for "" and "\p" */
  24.  
  25. /* struct to match patch header */
  26. typedef struct
  27. {    int        bra_instr;
  28.     long    check1, check2;
  29. } cheader;
  30.  
  31. #ifdef XCMD
  32. pascal main(paramPtr) XCmdPtr paramPtr;
  33. #else
  34. main()
  35. #endif
  36. {    register Ptr UNIMPLaddr;
  37.     register cheader **hp;
  38. #ifdef XCMD
  39.     Handle h;
  40.     register long ans;
  41. #else
  42. #ifndef INIT
  43.     /* patcher */
  44.     Str255 msg;
  45.     register msgnum;
  46. #endif
  47. #endif
  48.     
  49. #ifndef RSRC
  50.     /* patcher, use only in Finder */
  51.     InitGraf(&thePort);
  52.     InitFonts();
  53.     FlushEvents(everyEvent,0);
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs(NIL);
  58.     InitCursor();
  59.     
  60.     if( CautionAlert(2, NIL) == 1 ) return;
  61. #endif    
  62.     asm
  63.     {    move.w    #_Unimplemented,d0
  64.         _GetTrapAddress
  65.         move.l    a0,UNIMPLaddr
  66.         move.w    #_BitMapToRegion,d0
  67.         _GetTrapAddress    NEWTOOL
  68.         cmp.l    a0,UNIMPLaddr
  69. #ifdef INIT
  70.         bne.s    @systemTrap
  71. #else
  72.         beq.s    @patchit
  73.         cmp.l    #'np90',OFFSET(cheader,check1)(a0)
  74.         bne.s    @systemTrap
  75.         cmp.l    #'juri',OFFSET(cheader,check2)(a0)
  76.         bne.s    @systemTrap
  77. #ifndef XCMD
  78.         ; our trap - remove it
  79.         _RecoverHandle    SYS
  80.         _DisposHandle
  81.         move.l    UNIMPLaddr,a0
  82.         move.w    #_BitMapToRegion,d0
  83.         _SetTrapAddress    NEWTOOL
  84.         moveq    #2,msgnum
  85. #else
  86.         move.l    #'woz\0',ans
  87. #endif
  88.         bra.s    @display
  89.     patchit:
  90. #endif
  91.     }
  92.  
  93.     hp = (cheader **)GetNamedResource('TRAP', "\pBitMapToRegion");
  94.     if(hp == NIL) asm
  95.     {
  96. #ifdef INIT
  97.         move.w    #4,-(a7)
  98.         _SysBeep
  99.         bra.s    @bombLabel
  100. #else
  101. #ifdef XCMD
  102.         move.l    #'err\0',ans
  103. #else
  104.         moveq    #4,msgnum
  105. #endif
  106.         bra.s    @display
  107. #endif
  108.     } 
  109.     DetachResource((Handle)hp);
  110.     
  111.     asm
  112.     {    move.l    hp,a0
  113.         _MoveHHi        ; move to top of heap
  114.         _HLock            ; and lock it down
  115.         ; SetTrapAddress(_BitMapToRegion, StripAddress(*hp))
  116.         move.l    (a0),d0
  117.         _StripAddress
  118.         move.l    d0,a0
  119.         move.w    #_BitMapToRegion,d0
  120.         _SetTrapAddress    NEWTOOL
  121. #ifndef INIT
  122. #ifdef XCMD
  123.         move.l    #'add\0',ans
  124. #else
  125.         moveq    #1,msgnum
  126. #endif
  127.         bra.s    @display
  128. #endif
  129.     }
  130.  
  131. systemTrap:
  132. #ifdef XCMD
  133.     ans = 'sys\0';
  134. display:
  135.     asm
  136.     {    moveq    #4,d0
  137.         _NewHandle
  138.         move.l    a0,h
  139.         move.l    (a0),a0
  140.         move.l    ans,(a0)
  141.     }
  142.     paramPtr->returnValue = h;
  143. #else
  144. #ifndef INIT
  145.     msgnum = 3;
  146. display:
  147.     GetIndString(msg, 1, msgnum);
  148.     ParamText(msg, EMPTY, EMPTY, EMPTY);
  149.     NoteAlert(1, NIL);
  150. #else /* INIT */
  151. bombLabel:
  152.     ;    /* something must come after label */
  153. #endif
  154. #endif
  155. }